#include <stdio.h>

#define LEN 61

int main(int argc, char *argv[]) {

    int i, time[3] = { 0 };
    char a[LEN], b[LEN], c[LEN], d[LEN];
    char *week[] = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };

    scanf("%s%s%s%s", a, b, c, d);

    for (i = 0; i < LEN; i++) {
        if (a[i] == b[i]) {
            if (!time[0] && a[i] >= 'A' && a[i] <= 'G') {
                time[0] = a[i] - 'A' + 1;
                continue;
            }
            if (time[0] && !time[1]) {
                if (a[i] >= '0' && a[i] <= '9')
                    time[1] = a[i] - '0' + 1;
                else if (a[i] >= 'A' && a[i] <= 'N')
                    time[1] = a[i] - 'A' + 11;
            }
        }
    }

    for (i = 0; i < LEN; i++) {
        if (c[i] == d[i] && ((c[i] >= 'A' && c[i] <= 'Z') || (c[i] >= 'a' && c[i] <= 'z'))) {
            time[2] = i;
            break;
        }
    }

    printf("%s %02d:%02d\n", week[time[0] - 1], time[1] - 1, time[2]);

    return 0;
}
